package cn.itcast.demo.dao;

import cn.itcast.demo.pojo.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: taft
 * @Date: 2018-12-11 10:52
 */
@Component
public class FakeDao {

    @Autowired
    private RestTemplate restTemplate;


    String baseUrl = "http://user-service/user/hello/";

    @HystrixCommand(fallbackMethod = "queryUserByIdFallBack")
    public User queryUserById(Long id) {

        return restTemplate.getForObject(baseUrl+id,User.class);
    }


    //hystrix的回调方法一定要和原方法返回值类型一致，并且参数类型，参数的名称一致
    public User queryUserByIdFallBack(Long id) {

        User user = new User();
        user.setId(id);
        user.setName("当前查询有问题，请稍后重试");

        return user;
    }


}
